package com.lei.string;

/**
 * @author: leiGer
 * @Date: 2021/12/16
 * @Time: 1:11
 */
//判断两个字符串是否是变形字符串
public class IsFormation {
    public static boolean isFormation(String str1, String str2) {
        if (str1 == null || str2 == null || str1.length() != str2.length()) {
            return false;
        }
        char[]c1 = str1.toCharArray();
        char[]c2 = str2.toCharArray();
        int []arr = new int[256];
        for (int i = 0; i < c1.length; i++) {
            arr[c1[i]]++;
        }
        for (int i = 0; i < c2.length; i++) {
            if(arr[c2[i]]-- == 0){
                return false;
            }
        }
        return true;
    }
    public static void main(String[] args) {
        String str1 = "happy";
        String str2 = "yaphps";
        System.out.println(isFormation(str1, str2));
    }
}
